<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>借款申请</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
    <link href="../plugin/jquery-zoomify/zoomify.min.css" rel="stylesheet"/>

    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/local_zh.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/wangEditor-3.0.15/wangEditor.min.js"></script>
    <script src="../plugin/jquery-zoomify/zoomify.min.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../base/base.js'></script>

</head>

<body>

<script>
    $(function () {
        var resp = AjaxUtil.isLogin();
        if (!resp) return;
        var module = 'borrowing_apply_record';
        var query = [];
        var toolbar = {
            default: [false, false, false, false],// back;add;edit;remove
            dialog: [60, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [{
                name: '用户信用档案',
                glyphicon: 'user',
                onclick: 'showUserCreditFile',
            }]
        };
        // 表单内容配置
        var formElement = [{
            action: [false, true],
            type: 'hidden', // 表单类型
            name: 'serviceChargeId', // 字段名称
        }, {
            action: [false, true],
            type: 'number',
            label: '手续费用(%)',
            name: 'serviceRate',
        }];
        // 表格配置
        var bootstrapTable = {
            columns: [{
                radio: true
            }, {
                field: 'borrowingOrderNo',
                title: '借款单号',
                align: 'center',
            }, {
                field: 'email',
                title: '用户邮箱',
                align: 'center',
            }, {
                field: 'borrowingType',
                title: '借款币种',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 10) {
                        return 'BTC';
                    } else if (value == 20) {
                        return 'ETH';
                    } else if (value == 100) {
                        return 'BHPC';
                    }
                },
            }, {
                field: 'borrowingMoney',
                title: '借款金额',
                align: 'center',
            }, {
                field: 'mortgageType',
                title: '抵押币种',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 10) {
                        return 'BTC';
                    } else if (value == 20) {
                        return 'ETH';
                    } else if (value == 100) {
                        return 'BHPC';
                    } else {
                        return '未知';
                    }
                },
            }, {
                field: 'mortgageMoney',
                title: '抵押金额',
                align: 'center',
            }, {
                field: 'deadline',
                title: '期限',
                align: 'center',
            }, {
                field: 'rateType',
                title: '利率类型',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '天';
                    } else if (value == 2) {
                        return '月';
                    } else {
                        return '未知';
                    }
                },
            }, {
                field: 'interest',
                title: '借款利率(单位:%)',
                align: 'center',
            }, {
                field: 'refundWay',
                title: '还款方式',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '到期还本付息';
                    } else if (value == 2) {
                        return '等额本息';
                    } else if (value == 3) {
                        return '先息后本';
                    } else {
                        return '未知';
                    }
                },
            }, {
                field: 'applyDate',
                title: '申请时间',
                align: 'center',
                formatter: BootstrapTableUtil.formatter.datetime
            }, {
                field: 'checkStatus',
                title: '状态',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '申请中';
                    } else if (value == 2) {
                        return '已审批';
                    }
                },
            }, {
                field: 'checkStatus',
                title: '操作',
                align: 'left',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '<button class="btn btn-sm btn-warning" onclick="borrowing_apply_record.approval(' + row.borrowingRecordId + ',2)">审批</button> <button class="btn btn-sm btn-danger" onclick="borrowing_apply_record.approval(' + row.borrowingRecordId + ',-1)" >拒绝</button>'
                    } else if (value == 2) {
                        return '<button class="btn btn-sm btn-warning" onclick="borrowing_apply_record.makeLoans(' + row.borrowingRecordId + ',3)" >放款</button> <button class="btn btn-sm btn-danger" onclick="borrowing_apply_record.makeLoans(' + row.borrowingRecordId + ',-1)" >取消放款</button>'
                    } else {
                        return ''
                    }
                },
            }]
        };
        borrowing_apply_record = SingleTablePageCreateUtil.createInstance(module, query, toolbar, formElement, bootstrapTable);
        borrowing_apply_record.approval = function (borrowingRecordId, status) {
            var resp = AjaxUtil.postJson('borrowing_apply_record/approval', {
                borrowingRecordId: borrowingRecordId,
                checkStatus: status,
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#borrowing_apply_record_table').bootstrapTable('refresh');
            }
        }
        borrowing_apply_record.makeLoans = function (borrowingRecordId, status) {
            var resp = AjaxUtil.postJson('borrowing_apply_record/make_loans', {
                borrowingRecordId: borrowingRecordId,
                checkStatus: status,
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#borrowing_apply_record_table').bootstrapTable('refresh');
            }
        }
        borrowing_apply_record.showUserCreditFile = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#borrowing_apply_record_table');
            if (!row) return false;
            window.location.href = 'credit_file.html?userId=' + row.userId;
        };
    });
</script>
</body>

</html>